package hjslm.Controller.Background;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import hjslm.Bean.ExcellentStudentBean;
import hjslm.Common.Impl.CommonFunImpl;
import hjslm.Service.IBaseTwoService;
import hjslm.Service.IExcellentStudentService;
import hjslm.Service.ITeacherService;
import framework.base.common.Pager;
import framework.base.controller.BaseController;

/**
 * 优秀学员管理
 * @author fudum
 * @date 2014年12月1日
 */
@Controller
@RequestMapping("/b_excellentstudent")
public class ExcellentStudentController extends BaseController {

	/**
	 * @author fudum
	 */
	private static final long serialVersionUID = 1L;
	
	@Autowired
	IExcellentStudentService esService;
	
	
	@Autowired
	ITeacherService teacherService;
	
	@Autowired
	IBaseTwoService baseTwoService;

	@Override
	public void setLogger() {		
	}
	
	
	@RequestMapping("/index")
	public ModelAndView index(Pager<ExcellentStudentBean> pager) {
		ModelAndView modelAndView = new ModelAndView("background/excellentstudent/base/index");
		pager= esService.selectPage(null, pager);
		modelAndView.addObject("pager", pager);
		return modelAndView;
	}
	
	
	//添加优秀学员
	@RequestMapping("/add")
	public ModelAndView add(){
		ModelAndView modelAndView = new ModelAndView("background/excellentstudent/base/add");
		return modelAndView;
	}
	
	//编辑优秀学员
	@RequestMapping("/insert")
	public void insert(ExcellentStudentBean bean,HttpServletResponse response) {
		bean.setId(CommonFunImpl.uuid("ES"));
		bean.setInserttime(CommonFunImpl.currentTime(1));
		int retVal = esService.insert(bean);
		// 返回值
		try {
			PrintWriter out = response.getWriter();
			out.print(retVal);
			out.close();
		} catch (IOException e) {
			e.printStackTrace();// 打印异常
		}
	}
	
	/*
	 * 更新页面信息
	 */
	@RequestMapping("/update")
	public void update(ExcellentStudentBean bean,HttpServletResponse response) {
		bean.setInserttime(CommonFunImpl.currentTime(1));
		int retVal = esService.update(bean);
		// 返回值
		try {
			PrintWriter out = response.getWriter();
			out.print(retVal);
			out.close();
		} catch (IOException e) {
			e.printStackTrace();// 打印异常
		}
	}
	
	@RequestMapping("/edit")
	public ModelAndView edit(ExcellentStudentBean bean) {
		ModelAndView modelAndView = new ModelAndView("background/excellentstudent/base/edit");
		bean = esService.selectOne(bean);
		modelAndView.addObject("bean", bean);
		return modelAndView;
	}
	
	// 删除班级 4
	@RequestMapping("/delete")
	public void Delete(ExcellentStudentBean bean, HttpServletResponse response) {
		response.setCharacterEncoding("UTF-8");
		int ret = esService.delete(bean);
		// 以流的形式返回
		try {
			PrintWriter out = response.getWriter();
			out.print(ret);
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
}
